package com.kantboot.user.account.web.controller;

import com.kantboot.global.rest.result.CommonSuccessStateCodeAndMsg;
import com.kantboot.user.account.domain.dto.UserAccountSendVerificationCodeDTO;
import com.kantboot.user.account.service.IUserAccountBindService;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户账号绑定控制器
 */
@RestController
@RequestMapping("/user-account-web/userAccountBind")
public class UserAccountBindController {

    @Resource
    private IUserAccountBindService service;

    /**
     * 跳过绑定
     */
    @RequestMapping("/skipBind")
    public RestResult<Void> skipBind() {
        service.skipBind();
        return RestResult.success(null, CommonSuccessStateCodeAndMsg.SKIP_BIND_SUCCESS);
    }

    /**
     * 发送绑定验证码
     * @param sendVerificationCodeDTO 发送验证码的DTO
     */
    @RequestMapping("/sendBindVerificationCode")
    public RestResult<Void> sendBindVerificationCode(
            @RequestBody UserAccountSendVerificationCodeDTO sendVerificationCodeDTO) {
        service.sendBindVerificationCode(sendVerificationCodeDTO);
        return RestResult.success(null,CommonSuccessStateCodeAndMsg.SEND_VERIFICATION_CODE_SUCCESS);
    }

    /**
     * 绑定手机号
     * @param phoneAreaCode 手机区号
     * @param phone 手机号
     * @param verificationCode 验证码
     */
    @RequestMapping("/bindByPhoneAndVerificationCode")
    public RestResult<Object> bindByPhoneAndVerificationCode(
            @RequestParam("phoneAreaCode") String phoneAreaCode,
            @RequestParam("phone") String phone,
            @RequestParam("verificationCode") String verificationCode) {
        return RestResult.success(service.bindByPhoneAndVerificationCode(phoneAreaCode, phone, verificationCode),
                CommonSuccessStateCodeAndMsg.BIND_SUCCESS);
    }

    /**
     * 绑定邮箱
     * @param email 邮箱
     * @param verificationCode 验证码
     */
    @RequestMapping("/bindByEmailAndVerificationCode")
    public RestResult<Object> bindByEmailAndVerificationCode(
            @RequestParam("email") String email,
            @RequestParam("verificationCode") String verificationCode) {
        return RestResult.success(service.bindByEmailAndVerificationCode(email, verificationCode),
                CommonSuccessStateCodeAndMsg.BIND_SUCCESS);
    }

}
